package com.bxd.baodan.fragment;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.reflect.TypeToken;
import com.bxd.baodan.R;
import com.bxd.baodan.app.JsonApi;
import com.bxd.baodan.base.BaseListFragment;
import com.bxd.baodan.item.AdviserCommentItem;
import com.bxd.baodan.util.GlideUtil;
import com.bxd.baodan.util.NetUtil;
import com.bxd.baodan.widget.StarBarView;
import com.bxd.baodan.adapter.ViewHolder;

import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by lizhichao on 17/7/24.
 */

public class AdviserJudgeFragment extends BaseListFragment<AdviserCommentItem> {
    @Override
    protected void preDone(View v) {
        getData();
    }

    @Override
    protected int getFragmentLayout() {
        return R.layout.pull_refresh_layout;
    }

    @Override
    protected int getItemLayout() {
        return R.layout.adviser_judge_item;
    }

    @Override
    protected Type getTypeToken() {
        return new TypeToken<List<AdviserCommentItem>>() {
        }.getType();
    }

    @Override
    protected void setUsualNetUtil() {
        netUtil = new NetUtil(getActivity(),
                JsonApi.AGENT_COMMENTS);
    }

    @Override
    protected void convert(ViewHolder holder, AdviserCommentItem item) {


        ImageView imageAvtar;
        TextView tvName;
        TextView tvTime;
        StarBarView starBar;
        TextView score;
        TextView judge_content;


        imageAvtar = (ImageView) holder.getView(R.id.image_avtar);
        tvName = (TextView) holder.getView(R.id.tv_name);
        tvTime = (TextView) holder.getView(R.id.time_tv);
        starBar = (StarBarView) holder.getView(R.id.star_bar);
        score = (TextView) holder.getView(R.id.score);
        judge_content = (TextView) holder.getView(R.id.judge_content);

        GlideUtil.loadCircle(getActivity(), item.avatar, imageAvtar);
        judge_content.setText(item.content);


        score.setText(item.score + "分");


        String str = item.score.substring(0, 3);
        String intStar =  item.score.substring(0,1);

        float star = Float.parseFloat(str);
        starBar.setStarRating(star);
        starBar.setStarMaxNumber(Integer.parseInt(intStar));
        tvName.setText(item.realname == null && item.realname.isEmpty() ? item.nickname : item.realname);
        tvTime.setText(item.createTime);


    }

    @Override
    protected String getArrayStr(String json_data) {
        return "list";
    }
}
